package com.chuangjiangx.member.basic.web.config;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @author cj-ch
 * @date 2018/8/1 下午7:33
 */
@Configuration
@EnableScheduling
public class TaskConfig implements SchedulingConfigurer {

    @Override
    public void configureTasks(
            ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.setScheduler(scheduledThreadPoolExecutor());
//        taskRegistrar.addFixedRateTask(new IntervalTask(() -> sampleTask().initProRata(),1000*60*60*24L,1000L));
    }

    @Bean
    public ScheduledThreadPoolExecutor scheduledThreadPoolExecutor(){
        BasicThreadFactory threadFactory = new BasicThreadFactory
                .Builder()
                .namingPattern("member-h5-task-%d")
                .daemon(true)
                .build();
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(8,threadFactory);
        scheduledThreadPoolExecutor.setMaximumPoolSize(1024);
        return scheduledThreadPoolExecutor;
    }

//    @Bean
//    public SampleService sampleService(){
//        return new SampleService();
//    }
//    @Bean
//    public SampleTask sampleTask(){
//        return new SampleTask();
//    }


}
